import { reqGetCategoryListData, reqGetBannerListData, reqGetFloorListData } from '../../api/index';

// state中存储数据
const state = {
    //储存三级导航
    categoryList: [],
    bannerList: [],
    floorList: [],
};
// 多用于异步操作  比如发送ajax请求  不能直接操作state中的数据
const actions = {
    async getCategoryListData(context) {
        let result = await reqGetCategoryListData();
        if (result.code === 200) {
            context.commit('SAVE_CATEGORY_LIST_DATA', result.data);
        } else {
            console.log(result.message);
        }
    },
    async getBannerListData({ commit }) {
        let result = await reqGetBannerListData();
        // console.log(result);
        if (result.code === 200) {
            commit('SAVE_BANNER_LIST_DATA', result.data);
        }
    },
    async getFloorListData({ commit }) {
        let result = await reqGetFloorListData();
        if (result.code === 200) {
            commit('SAVE_FLOOR_LIST_DATA', result.data);
        }
    },
};

const mutations = {
    SAVE_CATEGORY_LIST_DATA(state, list) {
        state.categoryList = list;
    },
    SAVE_BANNER_LIST_DATA(state, bannerlist) {
        state.bannerList = bannerlist;
    },
    SAVE_FLOOR_LIST_DATA(state, floorlist) {
        state.floorList = floorlist;
    },
};

const getter = {};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getter,
};
